#!/bin/sh

## build.sh
## written by Anshu Chimala

cd src

echo "Cleaning"
make clean

echo "Building"
make

mv kernel ../kernel
cd ../

# echo "Building Bootflub"
# cd boot
# nasm Bootflub.s -f bin -o bootflub.bin

# cd ../

# echo "Creating floppy.img"
# rm floppy.img
# dd bs=512 count=2880 if=/dev/zero of=floppy.img
# mkfs.msdos floppy.img

echo "Writing Starflub to floppy.img"
sudo mkdir /media/tmp
sudo losetup /dev/loop0 floppy.img
sudo mount /dev/loop0 /media/tmp
sudo rm /media/tmp/kernel
sudo cp kernel /media/tmp/kernel
sudo cp utils/initrd.img /media/tmp/initrd

# echo "Writing Bootflub to floppy's bootsector"
# cd utils
# ./bootwriter ../boot/bootflub.bin ../floppy.img

echo
echo "Unmounting floppy.img"
sudo umount /media/tmp
sudo losetup -d /dev/loop0
sudo rm -rf /media/tmp

echo "Complete."

